const app = getApp();
import { countdown } from '../../../utils/util.js';

Component({
  /**
   * 组件的属性列表
   */
  properties: {
    goodsInfo: Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgUrl: app.data.imgurl,
    limitHours: '00',
    limitMin: '00',
    limitSecond: '00',
    limitTxt: '距降价'
  },

  ready: function () {
    this.initData();
  },

  pageLifetimes:{
    hide: function () {
      clearInterval();
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //初始化页面数据
    initData() {
      var t = { StartDate: '2019-06-20 12:20:20', EndDate: '2020-06-20 12:20:20'};  //测试给默认值
      let { CountDownSkuInfo } = this.data.goodsInfo;
      if (CountDownSkuInfo) t = CountDownSkuInfo;
      
      setInterval(() => {
        var c = countdown(t.StartDate)
        if (c.overTime) {
          c = countdown(t.EndDate);
          this.setData({limitTxt: '距结束'})
        }
        this.setData({
          limitHours: c.limitHours,
          limitMin: c.limitMin,
          limitSecond: c.limitSecond
        })
      }, 1000);
    },   
  }
})
